<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
if(!in_array('sign',$QXARR))exit(noauth());
require_once ZEAI.'cache/config_up.php';
require_once ZEAI.'sub/zeai_up_func.php';
$sign=json_decode($_ZEAI['sign'],true);
switch ($submitok) {
	case"alldel":
		if(empty($list))json_exit(array('flag'=>0,'msg'=>'请选择您要删除的信息'));
		if(!is_array($list))exit(JSON_ERROR);
		if(count($list)>=1){
			foreach($list as $v){
				$v=intval($v);
				$row = $db->ROW(__TBL_USER__,"sign_pdf_path,nickname,openid,subscribe","id=".$v);
				if ($row){
					$path_s = $row[0];$data_nickname = dataIO($row[1],'out');$data_openid = $row[2];$data_subscribe = $row[3];
					if (!empty($path_s)){
						@up_send_admindel($path_s.'|'.str_replace(".pdf",".png",$path_s));
					}
					$uid=$v;
					$db->query("UPDATE ".__TBL_USER__." SET sign_pdf_path='',sign_pdf_flag=0 WHERE id=".$uid);
					AddLog('驳回并删除用户【'.$data_nickname.'（uid:'.$v.'）】承诺书');
					//站内消息
					$C = $data_nickname.'您好，您的承诺书未通过审核，请重新签名';
					$db->SendTip($uid,"您的承诺书未通过审核",dataIO($C,'in'),'sys');
					//微信模版
					if (!empty($data_openid) && $data_subscribe==1){
						//审核通过提醒
						$keyword1 = urlencode('审核未通过');
						$keyword2 = urlencode('承诺书书写不规范，原因（不是本人姓名或潦草看不清），进入重新上传');
						$url      = HOST.'/m/my_sign.php';
						@wx_mb_sent('mbbh=ZEAI_DATA_CHECK&openid='.$data_openid.'&keyword1='.$keyword1.'&keyword2='.$keyword2.'&first='.$first.'&remark='.$remark.'&url='.$url);
					}
				}
			}
		}
		json_exit(array('flag'=>1,'msg'=>'操作成功'));
	break;
	case"allflag1":
		if(empty($list))json_exit(array('flag'=>0,'msg'=>'请选择您要审核的信息'));
		if(!is_array($list))exit(JSON_ERROR);
		if(count($list)>=1){
			foreach($list as $v){
				$v=intval($v);
				$row = $db->ROW(__TBL_USER__,"photo_s,nickname,openid,subscribe","id=".$v,"num");
				if ($row){
					$uid=$v;
					$photo_s = $row[0];$data_nickname = dataIO($row[1],'out');$data_openid = $row[2];$data_subscribe = $row[3];
					$photo_m = smb($photo_s,'m');
					$photo_b = smb($photo_s,'b');
					//站内消息
					$C = $data_nickname.'您好，您的承诺书已通过审核';
					$db->SendTip($uid,"您的承诺书已通过审核",dataIO($C,'in'),'sys');
					//微信模版
					if (!empty($data_openid) && $data_subscribe==1){
						//审核通过提醒
						$keyword1 = urlencode('审核通过');
						$keyword2 = urlencode('承诺书符合规范');
						$url      = HOST.'/m/my_sign.php';
						@wx_mb_sent('mbbh=ZEAI_DATA_CHECK&openid='.$data_openid.'&keyword1='.$keyword1.'&keyword2='.$keyword2.'&first='.$first.'&remark='.$remark.'&url='.$url);
					}
					$db->query("UPDATE ".__TBL_USER__." SET sign_pdf_flag=1 WHERE id=".$v);
					AddLog('审核用户【'.$data_nickname.'（uid:'.$uid.'）】承诺书->通过');
				}
			}
		}
		json_exit(array('flag'=>1,'msg'=>'审核成功'));
	break;
	case"ajax_watermark_up":
		if (ifpostpic($file['tmp_name'])){
			$dbname = 'p/tmp/sign_watermark.png';
			if (!up_send($file,$dbname,0,'2000*2000'))json_exit(array('flag'=>0,'msg'=>'图片写入失败'));
			AddLog('【承诺书防盗水印】上传图片->url:'.$dbname);
			json_exit(array('flag'=>1,'msg'=>'上传成功','dbname'=>$dbname));
		}else{
			json_exit(array('flag'=>0,'msg'=>'zeai_tmp_name_error'));
		}
	break;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
<script>var up2='<?php echo UP;?>',upMaxMB=<?php echo $_UP['upMaxMB']; ?>;</script>
<script src="js/up.js?<?php echo $_ZEAI['cache_str'];?>"></script>
</head>
<style>
.tablelist{width:100%;margin:0}
.tablelist td:hover{background-color:#fff}
.tablelist td{border:0}
.box{padding:0}

/*picadd*/
.picli{width:100%;margin:10px auto;display:-webkit-flex;display:flex;-webkit-flex-wrap:wrap;flex-wrap:wrap;-webkit-justify-content:space-between;justify-content:initial}
.picli li{width:130px;height:170px;line-height:100px;margin:10px 40px 30px 15px;background-color:#fff;position:relative;text-align:center;box-shadow:0 0 10px rgba(0,0,0,0.1);}
.picli li.flag0{background-color:#ffa}
.picli .add{background-image:url('images/picadd.png?3');background-size:120px 80px;background-repeat:no-repeat}
.picli li:hover{background-color:#F2F9FD}
.picli li img{vertical-align:middle;max-width:100px;max-height:100px;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;}
.picli li:hover .img{border:#fff 1px solid;cursor:zoom-in}

.picli li .del,.picli li .mod{background:#fff;color:#aaa;border:#eee 1px solid;line-height:20px;width:20px;height:20px;top:-10px;right:-10px;position:absolute;border-radius:12px;display:block}
.picli li .del:hover,.picli li .mod:hover{color:#000;cursor:pointer}
.picli li .del{font-size:12px}
.picli li .mod{font-size:14px;top:22px;}
.picli li .flagstr,.picli li .flagstr_1{width:30px;line-height:20px;color:#fff;font-size:12px;position:absolute;top:6px;left:-2px;background-color:#f70}

.picli li a.pic{display:block;padding:5px 0}
.picli li .f0{background-color:#ffc}
.picli li .nickname,
.picli li .chekbox{line-height:24px;height:24px;font-size:12px;color:#ddd;border-top:#eee 1px solid;font-family:'Verdana';overflow:hidden}
.picli li .chekbox{padding:5px}
.picli li .loveb{line-height:30px;padding-bottom:10px}
.picli li .chekbox .l{float:left}
.picli li .chekbox .l a{margin:0 2px 0 0}
.picli li .chekbox .r{float:right}
.picli li .chekbox .l a i{font-size:18px;color:#ccc}
.picli li:hover .chekbox .l a i:hover{color:#009688}
.picli li a span{display:block;width:100%;line-height:24px;position:absolute;top:28px;background-color:rgba(0,0,0,0.5);color:#aaa;font-size:12px}
</style>
<body<?php echo (ifint($uid))?' class="body"':'';?>>
<div class="box">
	<div class="boxL">
        <a href="sign.php?uid=<?php echo $uid;?>"<?php echo (empty($submitok))?' class="ed"':'';?>>承诺书列表</a>
        <a href="sign.php?submitok=set"<?php echo ($submitok=='set')?' class="ed"':'';?>>设置模版</a>
	</div>
	<div class="boxR">
    	<!--set start-->
    	<?php if ($submitok == 'set'){?>
    		<form id="W_W_W__A_9_A__C_N__FORM" enctype="multipart/form-data">
            <table class="table W98_ size2">
            <tr><th height="50" colspan="2" align="center" class="lineH150"><b class="S18">承诺书模版</b><div class="S12 C999"></div></th></tr> 
            <tr>
                <td class="tdL">上传pdf文件</td>
                <td class="tdR"><input name='imgFile' type='file' size='30' class='input size2' /> 　　<a href="<?php echo UP.'p/img/sign_mb.pdf?'.ADDTIME;?>" class="blue" target="_blank">查看当前服务器模版</a></td>
            </tr>    
            <tr>
            <td class="tdL"></td>
            <td class="tdR">如需要更换，请如下操作：<br>
            ① 下载word模版修改内容　<a href="images/sign_mb.doc" class="btn BAI size1"><i class="ico">&#xe669;</i> 下载模版</a>　<font class="Cf00">（注：内容必须只有一页，且内容不要超过整页一半高度，下半留空）</font> <br>
            ② 一般只要修改平台名称即可，改完文字后，另存为.pdf格式上传到后台</td>
            </tr>
            
            <tr><td class="tdL">防盗水印</td><td class="tdR">
            <div class="picli60" id="p_s_box1">
              <li class="add" id="p_s_btn1"></li>
              <?php
                $pspath_s1 = $sign['watermark'];
                if(!empty($pspath_s1)){
                    echo '<li><img src="'.UP.$pspath_s1.'"><i></i></li><span class="tips">先删除后更换(尺寸为：750*1061像素；.png格式半透明图片)，不需要水印，直接删除即</span>';
                }else{
					echo '<br><span class="tips">如需要加水印，请上传.png格式半透明图片，推荐尺寸为：750*1061像素</span>';
				}?>
            </div>
            
            </td></tr>
            
            <tr><td class="tdL">实名认证</td><td class="tdR">
            <input type="checkbox" name="ifidentity" id="ifidentity" class="switch" value="1"<?php echo ($sign['ifidentity'] == 1)?' checked':'';?>><label for="ifidentity" class="switch-label"><i></i><b>开启</b><b>关闭</b></label>　　<span class="tips2">开启后，必须实名认证后才可以签名</span>
            </td></tr>
            
            <tr><td class="tdL">真人认证</td><td class="tdR">
            <input type="checkbox" name="ifphoto" id="ifphoto" class="switch" value="1"<?php echo ($sign['ifphoto'] == 1)?' checked':'';?>><label for="ifphoto" class="switch-label"><i></i><b>开启</b><b>关闭</b></label>　　<span class="tips2">开启后，必须真人认证后才可以签名</span>
            </td></tr>
            
            <tr><td class="tdL">签名审核</td>
            <td class="tdR">
            <input type="checkbox" class="switch" name="flag" id="flag" value="1"<?php echo ($sign['flag'] == 1)?' checked':'';?>><label for="flag" class="switch-label"><i></i><b>开启</b><b>关闭</b></label>　　<span class="tips2">开启后，用户签名后将需要在（<a href="sign.php" class="blue">承诺书列表</a>）审核，审核通过后，个人主页将出现标识</span></td></tr>

            <tr>
              <td class="tdL">&nbsp;</td><td class="tdR">
            <button type="button" id="save" class="btn size3">保存设置</button>
            </td></tr>

            
            </table>
            <input name="submitok" type="hidden" value="sign_set_update">
            <input name="watermark" id="watermark" type="hidden" value="" />
            <input name="uu" type="hidden" value="<?php echo $session_uid;?>">
            <input name="pp" type="hidden" value="<?php echo $session_pwd;?>">
        	</form>
			<script>
			save.onclick = function(){
				zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,form:W_W_W__A_9_A__C_N__FORM},function(e){var rs=zeai.jsoneval(e);
					zeai.msg(rs.msg);
					if (rs.flag == 1){setTimeout(function(){location.reload(true);},1000);}
				});
			}
			adm_path_up({boxid:o(p_s_box1),btnid:o(p_s_btn1),inputid:o(watermark),url:'sign.php',submitok_add:'ajax_watermark_up'});
            </script>
        <?php }else{ ?>
        <!--set end-->
        <!--list start-->
        <div class="topsearch">
            <form name="ZEAI_CN__form1" method="get" action="<?php echo SELF; ?>">
                <input name="Skey" type="text" id="Skey" maxlength="25" class="input size2 W200" placeholder="按用户ID/昵称/手机" value="<?php echo $Skey; ?>">
                <input type="hidden" name="p" value="<?php echo $p;?>" />
                <button type="submit" class="btn size2"><i class="ico">&#xe6c4;</i> 搜索</button>
            </form>    
            <div class="rbox">

            </div>
        </div>
        <!---->
		<?php
        $SQL = "";
        $Skey = trimm($Skey);
        if (ifmob($Skey)){
			$SQL = " AND (mob=$Skey) ";
		}elseif(ifint($Skey)){
			$SQL = " AND (id=$Skey) ";
        }elseif(!empty($Skey)){
            $SQL = " AND ( ( uname LIKE '%".$Skey."%' ) OR ( nickname LIKE '%".$Skey."%' ) OR ( nickname LIKE '%".urlencode($Skey)."%' ) )";
        }
        if($t=='f1'){
            $SQL .= " AND flag=1 ";
        }elseif($t=='f2'){
            $SQL .= " AND flag=2 ";
        }
        $rt = $db->query("SELECT id,nickname,sex,grade,sign_pdf_path,sign_pdf_flag FROM ".__TBL_USER__." WHERE sign_pdf_path<>'' AND sign_pdf_flag>0 ".$SQL." ORDER BY sign_pdf_flag,id DESC LIMIT ".$_ADM['admLimit']);
        $total = $db->num_rows($rt);
        if ($total <= 0 ) {
            echo "<div class='nodataico'><i></i>暂无内容<br><a class='aQINGed' href='javascript:history.back(-1)'>返回上一步</a></div>";
        } else {
            $page_skin=2;$pagemode=3;$pagesize=27;require_once ZEAI.'sub/page.php';?>
            <form id="www_zeai_cn_FORM" method="get" action="<?php echo $SELF; ?>">
            <table class="tablelist">
            <tr style="display:none">
            <th width="20"><input type="checkbox" id="checkboxall1" class="checkskin checkboxall"><label for="checkboxall1" class="checkskin-label"><i class="i1"></i><b class="W50">全选</b></label></th>
            <th>&nbsp;</th>
            </tr>
            <tr>
            <td colspan="2">
              <div class="picli">
                <?php
                for($i=1;$i<=$pagesize;$i++) {
                    $rows      = $db->fetch_array($rt);if(!$rows) break;
                    $id        = $rows['id'];
                    $uid       = $id;
                    $nickname  = trimhtml(dataIO($rows['nickname'],'out'));
                    $sex       = $rows['sex'];
                    $grade     = $rows['grade'];
                    $sign_png_path   = str_replace(".pdf",".png",$rows['sign_pdf_path']);
                    $sign_pdf_path   = $rows['sign_pdf_path'];
                    $sign_pdf_flag   = $rows['sign_pdf_flag'];
                    //
                    if(empty($nickname))$nickname = $uname;
                    $nickname = str_replace($Skey,"<b class='Cf00'>".$Skey."</b>",$nickname);
                    //
                    $dst_s    = UP.$sign_png_path.'?'.$_ZEAI['cache_str'];
                    $dst_b    = $dst_s;
                    $flagbg   = ($sign_pdf_flag == 'W　w w .z e 　a i　.c n')?' class="flag0"':'';
                    $flagstr  = ($sign_pdf_flag == 2)?'<div class="flagstr">未审</div>':'';
                    $href     = Href('u',$uid);
                    $title2 = (!empty($nickname))?urlencode(trimhtml($nickname)).'／'.$uid:$uid;
                    $title2 = urlencode(trimhtml($nickname.' ｜ '.$uid));
                ?>
                <li<?php echo $flagbg; ?> id="tr<?php echo $id;?>" class="fadeInUp">
                  <a href="javascript:;" onClick="parent.piczoom('<?php echo $dst_b; ?>')" class="pic<?php if ($sign_pdf_flag == 2)echo ' f0'; ?>"><img src="<?php echo $dst_s; ?>" class="img"></a>
                  <a href="javascript:;" class="del" uid="<?php echo $uid;?>" title="删除"><font class="ico">&#xe606;</font></a>
                  <?php echo $flagstr; ?>
                  <div class="nickname"><a href="javascript:;" uid="<?php echo $uid;?>" title2="<?php echo $title2;?>" class="C999 photo_s"><?php echo uicon($sex.$grade) ?><?php echo $nickname; ?></a></div>
                  <div class="chekbox">
                    <div class="l">
                    	<a href="javascript:send_msg(<?php echo $uid; ?>,'<?php echo $nickname; ?>');" title="发送消息"><i class="ico">&#xe676;</i></a>　
                    	<a href="<?php echo UP.$sign_pdf_path.'?'.$_ZEAI['cache_str'];?>" title="下载pdf" target="_blank"><i class="ico">&#xe669;</i></a>
                    </div>
                      
                    <div class="r">
                      <input type="checkbox" class="checkskin" name="list[]" value="<?php echo $id; ?>" id="chk<?php echo $id; ?>" onclick="chkbox(<?php echo $i; ?>,<?php echo $id; ?>)"><label for="chk<?php echo $rows['id']; ?>" class="checkskin-label" title="选择"><i class="i1"></i></label>
                     </div>
                    </div>

                  </li>
                <?php }//end for ?>
              </div>
            </td>
            </tr>
            </table>
            </form>
		<?php }?>

		<!--list end-->
        <?php }?>
    </div>
    <div class="clear"></div>
</div>

<?php if ($total > 0 ) {?>
    <div class="listbottombox">
        <input type="checkbox" id="checkboxall2" class="checkskin checkboxall"><label for="checkboxall2" class="checkskin-label"><i class="i1"></i></label>　
        <button type="button" class="btn size2 HEI2 disabled action" id="btndellist">批量删除</button>　
        <button type="button" class="btn size2 LV disabled action"  id="btnflag">批量审核</button>　
        <button type="button" id="btnsend" value="" class="btn size2 disabled action" onClick="sendTipFn(this);"><i class="ico">&#xe676;</i> 发送消息</button>
        <input type="hidden" name="submitok" id="submitok" value="" />
        <?php if ($total > $pagesize)echo '<div class="pagebox FR">'.$pagelist.'</div>'; ?>
    </div>
    <script>
    var bg = '<?php echo $_Style['list_bg']; ?>',overbg = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';
	function send_msg(uid,nkname) {zeai.iframe('发送消息','u_tip.php?ulist='+uid,600,500);}
    zeai.listEach('.photo_s',function(obj){
        obj.onclick = function(){
            var uid = parseInt(obj.getAttribute("uid"));
            var title2 = obj.getAttribute("title2");
            var photo_s_url = decodeURIComponent(obj.getAttribute("photo_s_url"));
            crm_homepage({uid:uid,title2:title2,photo_s_url:photo_s_url});
        }
    });
	o('btndellist').onclick = function() {
		allList({
			btnobj:this,
			url:'sign'+zeai.ajxext+'submitok=alldel',
			title:'批量删除',
			msg:'正在删除中...',
			ifjson:true,
			ifconfirm:true
		});	
	}
	o('btnflag').onclick = function() {
		allList({
			btnobj:this,
			url:'sign'+zeai.ajxext+'submitok=allflag1',
			title:'批量审核',
			content:'<br>此操作将发送消息提醒推送（微信通知和站内信）',
			msg:'正在审核中...',
			ifjson:true,
			ifconfirm:true
		});	
		
	}
	zeai.listEach('.del',function(obj){
		obj.onclick = function(){
			var uid = parseInt(obj.getAttribute("uid"));
			zeai.confirm('真的要删除么？<br>删除后将自动发送驳回信息（微信通知和站内信），引导用户重新签名',function(){
				zeai.ajax('sign'+zeai.ajxext+'submitok=alldel&list[]='+uid,function(e){var rs=zeai.jsoneval(e);
					if (rs.flag == 1){location.reload(true);}else{zeai.msg(rs.msg);}
				});
			});
		}
	});
    </script>
    <script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php }?>
<?php require_once 'bottomadm.php';?>